package com.huawei.appgallery.purchasehistory.ui.fragment;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.HeaderViewListAdapter;
import android.widget.PopupWindow;
import android.widget.Toast;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol.Request;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.cardkit.widget.CardListAdapter;
import com.huawei.appgallery.foundation.ui.framework.fragment.AppListFragment;
import com.huawei.appgallery.foundation.ui.framework.widget.NodataWarnLayout;
import com.huawei.appgallery.purchasehistory.ui.bean.ConsumeRecordCardBean;
import com.huawei.appgallery.purchasehistory.ui.card.ConsumeRecordCard;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.framework.widget.RoundCornerLayout;
import o.cfv;
import o.cfw;
import o.cgi;
import o.cih;
import o.cii;
import o.cjk;
import o.cjm;
import o.cjo;
import o.cks;
import o.cku;
import o.cst.c;
import o.cst.d;
import o.cst.h;
import o.ctg;
import o.cvt;
import o.BaseRequest;
import o.dgm;
import o.djl;
import o.Logger;

public class ConsumeRecordsFragment extends AppListFragment {
    private PopupWindow ˊ;
    private boolean ॱॱ = false;
    private djl ᐝ;
    private Handler ﹳ;
    private String ﾞ;

    class b implements IServerCallBack {
        final /* synthetic */ ConsumeRecordsFragment ˊ;

        private b(ConsumeRecordsFragment consumeRecordsFragment) {
            this.ˊ = consumeRecordsFragment;
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            if (!this.ˊ.ॱ(responseBean) || this.ˊ.ॱॱ) {
                Toast.makeText(this.ˊ.ॱˊ(), this.ˊ.ॱ(h.ˎ), 0).show();
                this.ˊ.ٴ();
                return;
            }
            if (this.ˊ.ˊ(this.ˊ.ॱˋ())) {
                CardBean ˏ = this.ˊ.י.ˏ(this.ˊ.ﾞ);
                if (ˏ == null) {
                    Logger.ˎ("ConsumeRecordsFragment", "cannot find delete cardBean");
                } else {
                    Logger.ˎ("ConsumeRecordsFragment", "find the delete cardBean, cardBean id is " + ˏ.ॱॱ());
                }
                if (this.ˊ.י.ˊॱ() <= 0) {
                    this.ˊ.ˋॱ(false);
                } else if (this.ˊ.ͺˎ != null) {
                    CardListAdapter cardListAdapter;
                    if (this.ˊ.ͺˎ.getAdapter() instanceof HeaderViewListAdapter) {
                        cardListAdapter = (CardListAdapter) ((HeaderViewListAdapter) this.ˊ.ͺˎ.getAdapter()).getWrappedAdapter();
                    } else if (this.ˊ.ͺˎ.getAdapter() instanceof CardListAdapter) {
                        cardListAdapter = (CardListAdapter) this.ˊ.ͺˎ.getAdapter();
                    } else {
                        Logger.e("ConsumeRecordsFragment", "unknown listView adapter");
                        return;
                    }
                    if (cardListAdapter != null && cardListAdapter.getCount() > 0) {
                        cardListAdapter.notifyDataSetChanged();
                    }
                }
                this.ˊ.ˊ.dismiss();
                this.ˊ.ٴ();
            }
        }
    }

    public ConsumeRecordsFragment() {
        ˊʻ();
    }

    private void ˊʻ() {
        this.ﹳ = new Handler(this, Looper.getMainLooper()) {
            final /* synthetic */ ConsumeRecordsFragment ˏ;

            public void handleMessage(Message message) {
                if (message.what == 1 && this.ˏ.ˊ != null) {
                    this.ˏ.ˊ.dismiss();
                }
            }
        };
    }

    public boolean ͺˏ() {
        return true;
    }

    public cfv ˏ(String str, String str2, int i) {
        return cgi.ˏ(str, str2, i);
    }

    public void ᐝʼ() {
        super.ᐝʼ();
        this.ʼˊ = "consumeList";
    }

    public void ˏ(int i, cih o_cih) {
        if (i == 0) {
            ConsumeRecordCardBean consumeRecordCardBean = (ConsumeRecordCardBean) o_cih.ˌ();
            if (consumeRecordCardBean == null || consumeRecordCardBean.ॱॱ() == null) {
                Logger.ˋ("ConsumeRecordsFragment", "cardBean is null or detailId is null");
                return;
            }
            Context ॱˋ = ॱˋ();
            if (ॱˋ == null || ॱˋ.isFinishing()) {
                Logger.ˋ("ConsumeRecordsFragment", "activity is null or finishing");
            } else if (!cii.ˊ().ˊ(ॱˋ, consumeRecordCardBean)) {
                cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
                appDetailActivityProtocol.ˏ(new Request(consumeRecordCardBean.ॱॱ(), consumeRecordCardBean.u_()));
                cjk.ˎ().ˋ(ॱˋ, new cjm("appdetail.activity", appDetailActivityProtocol));
            }
        } else if (-1 == i) {
            ConsumeRecordCard consumeRecordCard = (ConsumeRecordCard) o_cih;
            this.ﾞ = ((ConsumeRecordCardBean) o_cih.ˌ()).ㆍ();
            ˋ(consumeRecordCard.ˉ());
        }
    }

    private void ˋ(View view) {
        if (this.ᴵ == null) {
            this.ᴵ = LayoutInflater.from(ॱˊ());
        }
        RoundCornerLayout roundCornerLayout = (RoundCornerLayout) this.ᴵ.inflate(d.ˊ, null);
        if (roundCornerLayout != null) {
            if (this.ˊ == null) {
                this.ˊ = new PopupWindow(roundCornerLayout, -2, -2, false);
                this.ˊ.setOutsideTouchable(true);
            }
            this.ˊ.showAsDropDown(view.findViewById(e.ˋ), -((int) ᐝॱ().getDimension(c.ॱ)), 0);
            roundCornerLayout.findViewById(e.ॱˋ).setOnClickListener(new OnClickListener(this) {
                final /* synthetic */ ConsumeRecordsFragment ˎ;

                {
                    this.ˎ = r1;
                }

                public void onClick(View view) {
                    this.ˎ.ˎ(this.ˎ.ॱˋ());
                }
            });
        }
    }

    private void ˎ(Context context) {
        cku ˏ = cku.ˏ(context, cku.class, null, ॱ(h.ˏ));
        ˏ.ॱ(-1, ॱ(h.ॱ));
        ˏ.ॱ(-2, ॱ(h.ˋ));
        ˏ.ˎ(context);
        ˏ.ॱ(new cks(this) {
            final /* synthetic */ ConsumeRecordsFragment ˎ;

            {
                this.ˎ = r1;
            }

            public void enableNetworking() {
                this.ˎ.י();
                cvt o_ctg = new ctg();
                o_ctg.setServiceType_(dgm.ˎ(this.ˎ.ॱˋ()));
                o_ctg.ˊ(this.ˎ.ﾞ);
                cfw.ˎ(o_ctg, new b());
            }

            public void upgrade() {
            }

            public void ˋ() {
            }
        });
        this.ﹳ.sendMessageDelayed(this.ﹳ.obtainMessage(1), 500);
    }

    private boolean ˊ(Activity activity) {
        return (activity == null || activity.isFinishing()) ? false : true;
    }

    private boolean ॱ(ResponseBean responseBean) {
        return responseBean != null && responseBean.getRtnCode_() == 0 && responseBean.getResponseCode() == 0;
    }

    private void י() {
        this.ᐝ = new djl(ॱˊ());
        this.ᐝ.setCancelable(true);
        this.ᐝ.ˋ(ॱ(h.ˋˊ));
        this.ᐝ.setCanceledOnTouchOutside(false);
        this.ᐝ.setOnCancelListener(new OnCancelListener(this) {
            final /* synthetic */ ConsumeRecordsFragment ˎ;

            {
                this.ˎ = r1;
            }

            public void onCancel(DialogInterface dialogInterface) {
                this.ˎ.ॱॱ = true;
            }
        });
        this.ᐝ.ˎ(500);
    }

    private void ٴ() {
        if (this.ᐝ == null) {
            Logger.e("ConsumeRecordsFragment", "Loading Dialog is null when stop it.");
            return;
        }
        this.ᐝ.ˏ();
        if (this.ᐝ.isShowing()) {
            try {
                this.ᐝ.dismiss();
                this.ᐝ = null;
            } catch (IllegalArgumentException e) {
                Logger.e("ConsumeRecordsFragment", "Loading Dialog IllegalArgumentException");
            }
        }
        this.ॱॱ = false;
    }

    public void ॱ(NodataWarnLayout nodataWarnLayout) {
        if (nodataWarnLayout != null) {
            nodataWarnLayout.setWarnImage(o.cst.b.ˊ);
            nodataWarnLayout.setWarnTextOne(h.ᐝॱ);
            nodataWarnLayout.setViewVisible(NodataWarnLayout.e.WARN_BTN, 8);
            nodataWarnLayout.setViewVisible(NodataWarnLayout.e.WARN_TEXTTWO, 8);
        }
    }
}
